<?php
//This class repersents the Project element
//Provides an interface to the project table in the DB
//and the html page showing the project
require_once('./inc/database.php');
require_once('./class/class.permissions.php');
require_once('./inc/functions.php');
require_once('./class/class.user.php');
require_once('./class/class.phpmailer.php');
db_connect();

class project
{
  private $project_id;
  public $project_name;
  public $project_description;
  public $project_start_date;
  public $project_end_date;
  public $project_customer;
  public $project_type;
  public $project_test_link;
  public $project_link;
  public $project_active;
  public $project_status;
  public $attachments;
  public $Quotation;//price offer
  public $FinalPrice;//final price
  public $DateQuotation;
  public $DateFinalPrice;
  public $Canceled;//select +','+ text
  
   public function __construct()
   	{
		  
		   $this->project_name="";
		   $this->project_description="";
		   $this->project_start_date="";
		   $this->project_end_date="";
		   $this->project_customer=null;
		   $this->project_type="";
		   $this->project_test_link="";
		   $this->project_link="";
		   $this->project_active=1;
		   $this->project_status=1;
		   $this->attachments="";
		   $this->Quotation="";
		   $this->FinalPrice="";
		   $this->DateQuotation="";
		   $this->DateFinalPrice="";
		   $this->Canceled="";
	}
	public static function createProjectFromArray($arrProject)
	{
		$proj= new project();

		foreach ($arrProject as $key=>$item)

		{ 

		  $proj->$key=$item;

		}
			return $proj;
	}
	
	
    public function getid()
		{
		 return $this->project_id;	
			
		}
		
		
		
		
	public function insert()
		{
			if($this->project_name!="")
			{
			 $stringinsert=sprintf("INSERT INTO `project`( `project_name`, `project_description`, `project_customer`, 
			 `project_start_date`, `project_end_date`, `project_type`, `project_test_link`,
			  `project_link`, `project_active`,`project_status`,`attachments`,`Quotation`,`FinalPrice`,`DateQuotation`,`DateFinalPrice`,`Canceled`)
			  	VALUES ('$this->project_name','$this->project_description',$this->project_customer,
			 '$this->project_start_date','$this->project_end_date','$this->project_type','$this->project_test_link',
			 '$this->project_link',$this->project_active,$this->project_status,'$this->attachments','$this->Quotation','$this->FinalPrice','$this->DateQuotation','$this->DateFinalPrice','$this->Canceled')");
			$queryinsert=mysql_query($stringinsert) or die(mysql_error().' '.$stringinsert);
			 
			 $this->project_id=mysql_insert_id();		
			 return true;
			}
			return 0;
		}
		
		
		
	public function update()
		{
			if($this->project_id!=null)
			{
 $stringupdate=sprintf("UPDATE `project` SET
                       `project_name`='$this->project_name',
					   `project_description`='$this->project_description',
					   `project_customer`=$this->project_customer,
					   `project_start_date`='$this->project_start_date',
					   `project_end_date`='$this->project_end_date',
					   `project_type`='$this->project_type',
					   `project_test_link`='$this->project_test_link',
					   `project_link`='$this->project_link',
					   `project_active`=$this->project_active,
					   `project_status`=$this->project_status,
					   `attachments`='$this->attachments',
					    `Quotation`='$this->Quotation',
					    `FinalPrice`='$this->FinalPrice',
						`DateQuotation`='$this->DateQuotation',
						`DateFinalPrice`='$this->DateFinalPrice',
						`Canceled`='$this->Canceled'
						WHERE project_id=$this->project_id
						  ");
						
			 $queryupdate=mysql_query($stringupdate) or die(mysql_error().' '.$stringupdate);
			 return true ;	
           	}
			return false;
		}
		
		
		
		
		
		
	public function getby_id($project_id)
		{
			$project_id=mysql_escape_string($project_id); 
		 	$stringgetby_id=sprintf("SELECT * FROM `project` WHERE `project_id`=$project_id");
			$querygetby_id=mysql_query($stringgetby_id) or die(mysql_error().' '.$stringgetby_id);
			$row=mysql_fetch_assoc($querygetby_id);
			if(mysql_affected_rows()>0)
				{
				   $this->project_id=$project_id;
				   $this->project_name=$row['project_name'];
				   $this->project_description=$row['project_description'];
				   $this->project_start_date=$row['project_start_date'];
				   $this->project_end_date=$row['project_end_date'];
				   $this->project_customer=$row['project_customer'];
				   $this->project_type=$row['project_type'];
				   $this->project_test_link=$row['project_test_link'];
				   $this->project_link=$row['project_link'];
				   $this->project_active=$row['project_active'];
				   $this->project_status=$row['project_status'];
				   $this->attachments=$row['attachments'];
				   $this->Quotation=$row['Quotation'];
				   $this->FinalPrice=$row['FinalPrice'];
				   $this->DateQuotation=$row['DateQuotation'];
				   $this->DateFinalPrice=$row['DateFinalPrice'];
				   $this->Canceled=$row['Canceled'];
				    return true;
				}
			return false;
		}
		
		
		
		
		
		public function getby_name($project_name)//update class project using the project name
		{
		 	$stringgetby_id=sprintf("SELECT * FROM `project` WHERE `project_name`='$project_name'");
			$querygetby_id=mysql_query($stringgetby_id) or die(mysql_error().' '.$stringgetby_id);
			$row=mysql_fetch_assoc($querygetby_id);
			if(mysql_affected_rows()>0)
				{
				   $this->project_id=$row['project_id'];
				   $this->project_name=$row['project_name'];
				   $this->project_description=$row['project_description'];
				   $this->project_start_date=$row['project_start_date'];
				   $this->project_end_date=$row['project_end_date'];
				   $this->project_customer=$row['project_customer'];
				   $this->project_type=$row['project_type'];
				   $this->project_test_link=$row['project_test_link'];
				   $this->project_link=$row['project_link'];
				   $this->project_status=$row['project_status'];
				   $this->attachments=$row['attachments'];
				   $this->Quotation=$row['Quotation'];
				   $this->FinalPrice=$row['FinalPrice'];
				   $this->DateQuotation=$row['DateQuotation'];
				   $this->DateFinalPrice=$row['DateQuotation'];
   				   $this->Canceled=$row['Canceled'];
				    return true;
				}
			return false;
		}
		
		
		
		
		
	public static function getallproject()//returns an array of all active projects
		{
		  $stringallpro=sprintf("SELECT * FROM `project` WHERE `project_active`=1");
		  $queryallpro=mysql_query($stringallpro) or die (mysql_error().' ' .$stringallpro);	
		  $arr=array();
		  while($row=mysql_fetch_assoc($queryallpro))
		  {
			 array_push($arr,$row['project_id']);
			     
		  }
		  return $arr;
			
		}
		
		
		
		
		
		
	public static function getallproject_admin()//returns an array of all projects
		{
		  $stringallpro=sprintf("SELECT * FROM `project` ");
		  $queryallpro=mysql_query($stringallpro) or die (mysql_error().' ' .$stringallpro);	
		  $arr=array();
		  while($row=mysql_fetch_assoc($queryallpro))
		  {
			 array_push($arr,$row['project_id']);
			     
		  }
		  return $arr;
			
		}
		
		
		
		
	public function get_contect_customer()//return customer contact person information
		{
		 	$st=sprintf("SELECT * FROM `user` WHERE `user_customer`=$this->project_customer 
			              and `role_type`=4 and `send_mail`=1");
						  
			$query=mysql_query($st)or die (mysql_error().' '.$st);
		   if(mysql_affected_rows()>0)
		   	{   $arr=array();
				while($row=mysql_fetch_assoc($query))
				 {
					$temp=new user();
					$temp->getby_id($row['user_id']);
					array_push($arr,$temp);
				 }
			   return $arr;	 
			} 
			else 
			  {
			   return 0;	
			  }
		   	
		}
			
	public  function get_customer_name($customer_id)// gets customer id and returns customer name 	
		{
			$stringCustomer_N=sprintf("SELECT * FROM `customer` WHERE Id=$customer_id");
			$queryCustomer_N=mysql_query($stringCustomer_N) or die (mysql_error().' '.$stringCustomer_N);
			
			if(mysql_affected_rows()>0)
				{
					$row=mysql_fetch_assoc($queryCustomer_N);
				     return $row['customer_name'];	
				}
			else 
				{
				 return false;	
				}
		}
		
		
public static function get_all_customer()
{
  $st=sprintf("SELECT * FROM `customer` WHERE `Active`=1");
  $query=mysql_query($st)or die (mysql_error(). ' '. $st);
  $arr=array();
 if(mysql_affected_rows()>0)
  {
  while($row=mysql_fetch_assoc($query))
    {
	  $arr[$row['Id']]= $row['customer_name']; 	
	}
	return $arr;
  }
  else return 0;
}
public static function get_all_project_of_customer($id_customer)
{
   $st=sprintf("
					SELECT c.customer_name, p.project_name, t. * 
					FROM project AS p
					INNER JOIN task AS t ON ( p.project_id = t.project_id ) 
					INNER JOIN customer AS c ON ( c.Id = p.project_customer ) 
					WHERE p.project_customer =$id_customer
					ORDER BY p.project_id, t.task_date DESC , t.task_time DESC 
			  ");	
   $query=mysql_query($st)or die (mysql_error().' '.$st);
   $arr=array();
   if(mysql_affected_rows()>0)
   {
	 while($row=mysql_fetch_assoc($query))
	  {
		 	
		  array_push($arr,$row);
	  }
	 return $arr; 
   }
   
  else  
    {
	  return 0;	
	}
}
public static function get_status_project_of_customer($id_customer,$status)
{ 
   $st=sprintf("SELECT * FROM `project` WHERE `project_customer`=$id_customer AND project_active=1 AND project_status=$status");	
   $query=mysql_query($st)or die (mysql_error().' '.$st);
   $arr=array();
   if(mysql_affected_rows()>0)
   {
	 while($row=mysql_fetch_assoc($query))
	  {
		  $project = new project;
		  $project->getby_id($row['project_id']);
		  array_push($arr,$project);
	  }
	 return $arr; 
   }
   
  else  
    {
	  return 0;	
	}
}

		public function getby_project_id()// returns all permissions for a project
			{
			  	$stringby_pro=sprintf("SELECT * FROM `permissions` WHERE  `project_id`=$this->project_id AND Active=1");
				$qeuryby_pro=mysql_query($stringby_pro) or die (mysql_error().' '.$stringby_pro);
				if(mysql_affected_rows()>0)
				{
				$arr=array();
				while($row=mysql_fetch_assoc($qeuryby_pro))
					{
					 $temp=new  permissions();
					 $temp->project_id=$this->project_id;
					 $temp->user_id=$row['user_id'];
					 $temp->role_type=$row['role_type'];
					  array_push($arr,$temp);	
					
					}
					$user_contact=user::get_user_contects($this->project_customer);
					if($user_contact!=0)
					{
					   foreach($user_contact as $single_contact)
					    {
						     $temp=new  permissions();
							 $temp->project_id=$this->project_id;
							 $temp->user_id=$single_contact->getuser_id();
							 $temp->role_type=$single_contact->role_type;
							array_push($arr,$temp);	
					    }
					}
					
					
					return $arr;
				}
				else 
				{ 
				return 0;
				}
			}
			
			
			
			
			
		public function get_tasks($limit=100)// returns array of all project tasks 
			{
			 $stringtask=sprintf("SELECT * FROM `task` WHERE
			  `project_id`=$this->project_id order by 	task_date DESC ,task_time DESC LIMIT $limit");
			 $querytask=mysql_query($stringtask) or die(mysql_error().' '.$stringtask);	
			 $arr=array();
			 if(mysql_affected_rows()>0)
				 {
				  while($row=mysql_fetch_assoc($querytask))
					{
						
						array_push($arr, $row);
						
					}
					return $arr;
				}
				
			  return 0;
			}
public function get_tasks_in_status($id_status)
{
    $st=sprintf("SELECT * FROM `task` WHERE  `project_id`=$this->project_id  and`task_status_id`=$id_status");
	$query=mysql_query($st)or die(mysql_error().' '.$st);
	$arr=array();
			 if(mysql_affected_rows()>0)
				 {
				  while($row=mysql_fetch_assoc($query))
					{
						array_push($arr,$row['task_id']);
						
					}
					return $arr;
				}
				
			  return 0;
}
public function get_tasks_in_option($status,$from,$to) //get tasks:
{

 if(!empty($status) && !empty($from) && !empty($to))//by status and date
 	{
	  	 $st=sprintf("SELECT * FROM `task` WHERE 
		 			 `project_id`=$this->project_id 
		  			 AND `task_status_id`=$status
		   			 AND `task_date` BETWEEN '$from' AND '$to' ");
					 
	}
	
	elseif(empty($status) && !empty($from) && !empty($to)) //by date only
	   {
		   $st=sprintf("SELECT * FROM `task` WHERE 
		 			 `project_id`=$this->project_id 
		  			  AND `task_date` BETWEEN '$from' AND '$to' ");
					  
 	    }
	elseif(empty($status) && !empty($from) && empty($to)) //by - from date
	   {
		   $st=sprintf("SELECT * FROM `task` WHERE 
		 			 `project_id`=$this->project_id 
		  			  AND `task_date` >= '$from' ");
					  
 	    }	
	elseif(empty($status) && empty($from) && !empty($to)) //by - to date
	   {
		   $st=sprintf("SELECT * FROM `task` WHERE 
		 			 `project_id`=$this->project_id 
		  			  AND `task_date` <= '$to' ");
					  
 	    }	
	elseif(!empty($status) && !empty($from) && empty($to)) //by status and from date
	   {
		   $st=sprintf("SELECT * FROM `task` WHERE 
		 			 `project_id`=$this->project_id 
					  AND `task_status_id`=$status
		  			  AND `task_date` >= '$from' ");
					  
 	    }	
	elseif(!empty($status) && empty($from) && !empty($to)) //by status and to date
	   {
		   $st=sprintf("SELECT * FROM `task` WHERE 
		 			 `project_id`=$this->project_id 
					  AND `task_status_id`=$status
		  			  AND `task_date` <= '$to' ");
					  
 	    }	
	elseif(!empty($status) && empty($from) && empty($to)) //by status
	   {
		   $st=sprintf("SELECT * FROM `task` WHERE 
		 			 `project_id`=$this->project_id 
					  AND `task_status_id`=$status  ");
					  
 	    }
	else 
		{
		  return;	
		}
	
	$query=mysql_query($st)or die(mysql_error().' '.$st);
	$arr=array();
			 if(mysql_affected_rows()>0)
				 {
				  while($row=mysql_fetch_assoc($query))
					{
						array_push($arr,$row);
						
					}
					return $arr;
				}
				
			  return 0;
	
}

public static function get_project_in_option($id_customer,$status,$from,$to)//get project
{

 if(!empty($status) && !empty($from) && !empty($to))//by status and date
 	{
	  	 $st=sprintf(" SELECT * FROM `project` WHERE
		             `project_customer`=$id_customer AND
					 `project_status`=$status   AND 
					 `project_start_date` BETWEEN '$from' AND '$to'  ");
					
					 
	}
	
	elseif(empty($status) && !empty($from) && !empty($to)) //by date
	   {
		   $st=sprintf("SELECT * FROM `project` WHERE
		             `project_customer`=$id_customer 
		  			  AND `project_start_date` BETWEEN '$from' AND '$to' ");
					  
 	    }
	elseif(empty($status) && !empty($from) && empty($to)) //by - from date
	   {
		   $st=sprintf("SELECT * FROM `project` WHERE
		             `project_customer`=$id_customer 
		  			  AND `project_start_date` >= '$from' ");
					  
 	    }	
	elseif(empty($status) && empty($from) && !empty($to)) //by - to date
	   {
		   $st=sprintf("SELECT * FROM `project` WHERE
		             `project_customer`=$id_customer
		  			  AND `project_start_date` <= '$to' ");
					  
 	    }	
	elseif(!empty($status) && !empty($from) && empty($to)) //by status and from date
	   {
		   $st=sprintf("SELECT * FROM `project` WHERE
		             `project_customer`=$id_customer
					  AND
					 `project_status`=$status   AND 
					 `project_start_date` >= '$from' ");
					  
 	    }	
	elseif(!empty($status) && empty($from) && !empty($to)) //by status and to date
	   {
		   $st=sprintf("SELECT * FROM `project` WHERE
		             `project_customer`=$id_customer AND
					 `project_status`=$status   AND 
					 `project_start_date` <= '$to' ");
					  
 	    }	
	elseif(!empty($status) && empty($from) && empty($to)) //by status
	   {
		   $st=sprintf("SELECT * FROM `project` WHERE
		             `project_customer`=$id_customer AND
					 `project_status`=$status  ");
					  
 	    }
	else 
		{
		  return 0;	
		}
	
	$query=mysql_query($st)or die(mysql_error().' '.$st);
	$arr=array();
			 if(mysql_affected_rows()>0)
				 {
				  while($row=mysql_fetch_assoc($query))
					{
						array_push($arr,$row['project_id']);
						
					}
					return $arr;
				}
				
			  return 0;
	
}
								
public  function get_status_project()//returns project status
			{ 
			    $stringstatus=sprintf("SELECT * FROM `project_status` WHERE  project_status_id=$this->project_status");
				$querystatus=mysql_query( $stringstatus)or die(mysql_error().' '. $stringstatus);
				$row=mysql_fetch_assoc($querystatus);
				return $row['project_status'];	
				
			}
	  
	  
public static function get_status_project2($id)//returns project status
{ 
	$stringstatus=sprintf("SELECT * FROM `project_status` WHERE  project_status_id=$id");
	$querystatus=mysql_query( $stringstatus)or die(mysql_error().' '. $stringstatus);
	$row=mysql_fetch_assoc($querystatus);
	return $row['project_status'];	
	
}	  
	  
public static function get_name($id_project)// gets project id and returns project name
{
	$st=sprintf("SELECT * FROM `project` WHERE `project_id`= $id_project");
	$query=mysql_query($st)or die(mysql_error().' '.$st);
	$row=mysql_fetch_assoc($query);
	return $row['project_name'];
	
}



public static function get_in_development($status)//returns count of project in development 
	{
		$st=sprintf("SELECT * FROM `project` WHERE `project_status`='$status'");
		$query= mysql_query($st)or die (mysql_error().' '.$st);
		return mysql_affected_rows();
		
	}
	
public function selector()//search for tasks by project section
{?>    
      <div id="div_selector" class="info_link">
      	<fieldset>
           <label for="from">מתאריך:</label>
          <input type="text" id="from" name="from"/>
          <label for="to">עד תאריך:</label>
          <input type="text" id="to" name="to"/>
          
          <select id="selector_status" name="selector_status">
               <option value="0">בחר סטאטוס</option>
               <option value="1">חדש</option>
               <option value="2">התקבל</option>
               <option value="3">בטיפול</option>
               <option value="4">טופל</option>
               <option value="5">נדחה</option>
           </select>
           
           <a id="send_selector" name="send_selector"   >סנן</a>
       </fieldset>
       </div>
       <script>
        $(document).ready(function(e) {
             $('#send_selector').click(function(e) {
                
					  
							selector_all_option(<?php echo $this->project_id; ?>,$("#selector_status").val(),
												$('#from').val(), $('#to').val());	
            });
			$(function() {
		var dates = $( "#from, #to" ).datepicker({
			defaultDate: "+1w",
			changeMonth: true,
			numberOfMonths: 1,
			changeYear: true,
			dayNamesMin: ['א', 'ב', 'ג', 'ד', 'ה', 'ו', 'ש'],
			isRTL: true,
			monthNamesShort: ['ינו','פבר','מרץ','אפר','מאי','יונ','יול','אוג','ספט','אוק','נוב','דצמ'], 
			prevText: '',
			nextText: '',
			dateFormat:'yy-mm-dd',
			onSelect: function( selectedDate ) {
				var option = this.id == "from" ? "minDate" : "maxDate",
					instance = $( this ).data( "datepicker" ),
					date = $.datepicker.parseDate(
						instance.settings.dateFormat ||
						$.datepicker._defaults.dateFormat,
						selectedDate, instance.settings );
				dates.not( this ).datepicker( "option", option, date );
			}
		});
	});
			
        });
		
       </script> 
       
<?php }
public static function selector_customer($id_customer)//search for tasks by date
{?>    
      <div id="div_selector" class="info_link">
      	<fieldset>
           <label for="from">מתאריך:</label>
          <input type="text" id="from" name="from"/>
          <label for="to">עד תאריך:</label>
          <input type="text" id="to" name="to"/>
          
          <!--<select id="selector_status" name="selector_status">
               <option value="0">בחר סטאטוס</option>
               <option value="1">חדש</option>
               <option value="2">התקבל</option>
               <option value="3">בטיפול</option>
               <option value="4">טופל</option>
               <option value="5">נדחה</option>
           </select>-->
           
           <a id="send_selector" name="send_selector"   >סנן</a>
       </fieldset>
       </div>
       <script>
        $(document).ready(function(e) {
             $('#send_selector').click(function(e) {
                
					  
							selector_all_option_customer(<?php echo $id_customer; ?>,$('#from').val(), $('#to').val());
					
            });
			$(function() {
		var dates = $( "#from, #to" ).datepicker({
			defaultDate: "+1w",
			changeMonth: true,
			numberOfMonths: 1,
			changeYear: true,
			dayNamesMin: ['א', 'ב', 'ג', 'ד', 'ה', 'ו', 'ש'],
			isRTL: true,
			monthNamesShort: ['ינו','פבר','מרץ','אפר','מאי','יונ','יול','אוג','ספט','אוק','נוב','דצמ'], 
			prevText: '',
			nextText: '',
			dateFormat:'yy-mm-dd',
			onSelect: function( selectedDate ) {
				var option = this.id == "from" ? "minDate" : "maxDate",
					instance = $( this ).data( "datepicker" ),
					date = $.datepicker.parseDate(
						instance.settings.dateFormat ||
						$.datepicker._defaults.dateFormat,
						selectedDate, instance.settings );
				dates.not( this ).datepicker( "option", option, date );
			}
		});
	});
			
        });
		
       </script> 
       
<?php }
public function get_html_project()// project page format
		 {?>
             <div id="content_project">
               <div id="static_info">
             	<div id="basic_info">
            		<div class="box_btn" id="project_toggle<?php echo $this->project_id; ?>" onclick="project_toggle(<?php echo $this->project_id; ?>)">+</div>
                 	
                                          <span class="single_info">
                                          	  <span class="color_turkiz" >אנשי קשר: </span>
                                               <?php 
                                                $permissionsUser=$this->getby_project_id();
                                                if ($permissionsUser){
                                                      foreach( $permissionsUser as $temp)
                                                             { 
                                                                if($temp->role_type==5){echo user::get_name($temp->user_id);}
                                                             }  
												}
                                                 ?>
                                                 .
                                          </span>
                                          
                                 
                                          <span class="single_info">
                                          	  <span class="color_turkiz">מפתחים: </span>
                                             <?php   $flag=false;
                                             if ($permissionsUser){
                                                       foreach($permissionsUser as $temp)
                                                             {  
                                                                if($temp->role_type==2)
																   {
																	if($flag){echo ',';$flag=false;}
																	echo user::get_name($temp->user_id);$flag=true;
																	}
                                                             }
                                               } 
                                             ?>
                                             .
                                          </span>
                                             
                             
                                        <span class="single_info">
                                        	  <span class="color_turkiz">בדיקות תוכנה: </span>
                                           <?php   $flag=false;
                                           		if ($permissionsUser){
                                                     foreach($permissionsUser as $temp)
                                                           {  if($flag){echo ',';$flag=false;}
                                                              if($temp->role_type==3){echo user::get_name($temp->user_id);$flag=true;}
                                                           } 
                                                }
                                           ?>
                                           .
                                        </span>
                                        
                               
                                <span class="single_info">
                                	   <span class="color_turkiz" >תאריך תחילה: </span>
                                     <?php 
                                          $date=$this->project_start_date;
                                          $date=explode('-',$date);
                                          echo $date[2].'/'.$date[1].'/'.$date[0];
                                       ?>
                                       .
                                </span> 
                                 
                               
                                <span class="single_info">
                                		 <span class="color_turkiz" >תאריך סיום: </span>
                                     <?php 
                                          $date=$this->project_end_date;
                                          $date=explode('-',$date);
                                          echo $date[2].'/'.$date[1].'/'.$date[0];
                                       ?>
                                       .
                                </span> 


                    	<div class="info_link">
                             <span class="color_turkiz single_info" >קישור לפרוייקט: </span>
                             <a href="<?php echo  isHTTP($this->project_link); ?>" target="_blank">לפרויקט</a>
                             <input type="text" readonly="readonly" value="<?php echo $this->project_link; ?>" /> 
                        </div>
                        <div class="info_link">
                             <span class="color_turkiz single_info" >קישור לסביבת הפיתוח: </span>
                             <a href="<?php echo isHTTP($this->project_test_link); ?>" target="_blank">לפיתוח</a>
                             <input type="text" readonly="readonly" value="<?php echo $this->project_test_link; ?>" /> 
                        </div> 
                         
         </div><!--basic_info-->
         
         <div id="status_box" class="status_box">
             <p>
                <span class="color_turkiz status_box_right_span" >הלקוח: </span>
                    <span class="status_box_left_span">
                         <?php 
                                echo $this->get_customer_name($this->project_customer);
                           ?>
                    </span>
             </p>
             <p>
             <span class="color_turkiz status_box_right_span" >סוג: </span>
                 <span class="status_box_left_span">
                     <?php 
                            echo $this->project_type;
                       ?>
                </span>
             </p>
             <p>
             <span class="color_turkiz status_box_right_span" >סטאטוס: </span>
                 <span class="status_box_left_span">
                     <?php 
                            echo $this->get_status_project();
                       ?>
                </span>
                
             </p>
            
         </div><!--status_box-->
        </div><!--static_info--> 
           
            <div id="expanding_info<?php echo $this->project_id ?>" class="expanding_info">
              
              <span class="color_turkiz">תיאור הפרוייקט: </span>
              <p><?php echo $this->project_description; ?>.</p>
              
               <? if($this->Canceled!="none" && $this->Canceled!=""){ ?>
             <div style="float:right; width:100%;">
              <span class="color_turkiz status_box_right_span" >סיבת הביטול: </span>
                 <span class="status_box_left_span">
                     <?php 
					        $cancel=explode(',',$this->Canceled);
                            echo project::GetNameListCanceled($cancel[0]).', ';
							echo $cancel[1];
                       ?>
                </span>
             </div>
             <? } ?>
             
             <span class="color_turkiz status_box_right_span" >קבצים מצורפים: </span>
             <div class="project_attachments" >
              <?php if(!$this->attachments=="")
			  			{
						 $ArrFileAttach=explode(',',$this->attachments);
						 foreach($ArrFileAttach as $SingleFile)
						 {	
							?>
                <div class="project_attachment_holder" style="clear:none;">
                <? $NameFileFull=explode('*-*',$SingleFile);
                $NameFile=substr($NameFileFull[1],0,strrpos($NameFileFull[1],'.')); 	?>
                <a id="attachments_project" href="<?php echo $SingleFile;?>" target="_blank" title="<? echo $NameFileFull[1]; ?>"><? echo mb_substr($NameFile,0,16); if(mb_strlen($NameFile)>16){?>...<? } ?></a>
                </div>
			      <?php }}
			  ?>
              </div>
              
              <?php  $user = new user();
			         $user->getby_name($_SESSION['user']);
					 
			  if($user->role_type!=4 && $user->role_type!=5 ){ ?>
             
                 <? if($user->role_type==1){ ?>
                  <div id="Quotation_FinalPrice">
                   <div class="form_set_price ">
                   <label class="color_turkiz">הצעת מחיר: </label>
                   <input name="Quotation" type="text" value="<? echo $this->Quotation; ?>" />
                   <? $today = getdate(); ?>
                   <label class="color_turkiz">תאריך:</label>
                   <input name="DateQuotation" id="DateQuotation" readonly="readonly"
                   class="hasDatepicker" value="<?  echo $this->DateQuotation; ?>" />
                  </div>
                  <div class="form_set_price">
                   <label class="color_turkiz">מחיר סופי: </label>
                   <input name="FinalPrice" type="text" value="<? echo $this->FinalPrice; ?>" />
                   <? $today = getdate(); ?>
                   <label class="color_turkiz" id="LblDateFinalPrice">תאריך:</label>
                   <input name="DateFinalPrice" id="DateFinalPrice" readonly="readonly"
                    class="hasDatepicker" value="<?  echo $this->DateFinalPrice;  ?>" />
                  </div>
                  </div>
                 <? } ?>
              
              <div id="access_details">
              <span class="color_turkiz">פרטי גישה: </span>
               <?php $access_details=new pad();
			          $access_details->getby_id($this->getid());
			   ?>
                       <table>
                          <thead>
                             <th></th>
                             <th>FTP</th>
                             <th>DB</th>
                             <th>מערכת ניהול</th>
                             <th>Cpanel</th>
                          </thead>
                          <tbody> 
                            <tr>
                              <td class="color_turkiz">כתובות</td>
                              <td><?php echo $access_details->ftp_address ?></td>
                              <td><?php echo $access_details->db_address ?></td>
                              <td><?php echo $access_details->manager_address ?></td>
                              <td><?php echo $access_details->cp_address ?></td>
                            </tr>
                            <tr>
                              <td class="color_turkiz">משתמש</td>
                              <td><?php echo $access_details->ftp_user ?></td>
                              <td><?php echo $access_details->db_user ?></td>
                              <td><?php echo $access_details->manager_user ?></td>
                              <td><?php  echo $access_details->cp_user?></td>
                            </tr>
                            <tr>
                              <td class="color_turkiz">סיסמא</td>
                              <td><?php echo $access_details->ftp_pass ?></td>
                              <td><?php echo $access_details->db_pass ?></td>
                              <td><?php echo $access_details->manager_pass ?></td>
                              <td><?php  echo $access_details->cp_pass?></td>
                            </tr>
                            <tr>
                              <td class="color_turkiz">שם</td>
                              <td></td>
                              <td><?php echo $access_details->db_name ?></td>
                              <td> </td>
                              <td> </td>
                            </tr>
                          
                          </tbody>
                       </table>
               			</div><!--access_details-->
                        <?php }; ?>
                        
                 </div><!--expanding_info-->
             </div><!--content_project-->
             
             
             
             
             
             
             
            <script>
              $(document).ready(function(e) {
               
				
					/***********************/
				
				/***adjustment to status_box and basic_info location **/
				basic_info_h = $("#basic_info").height();
				$(".status_box").height(basic_info_h);
			  
            });
            </script>
             
       <?php } 

public static function GetListStatusProject()
{
   $st=sprintf("SELECT * FROM `project_status`");
   $query=mysql_query($st) or die(mysql_error().' '.$st);	
	
	while($row=mysql_fetch_assoc($query))
		{
          $sid=$row['project_status_id'];
		  $sname=$row['project_status'];
		  echo "<option value='$sid' >$sname</option>";	
		}	
}
public function GetListCanceledOfProject()
{  
   $cancel=explode(',',$this->Canceled);
   $st=sprintf("SELECT * FROM Canceled");
   $query=mysql_query($st) or die(mysql_error().' '.$st);
   ?>	
	<option value='none' <? if($cancel[0]=='none'){?> selected='selected' <? }  ?>  >בחר סיבת דחיה</option>
    <?	
	while($row=mysql_fetch_assoc($query))
		{
          $sid=$row['Id'];
		  $sname=$row['CanceledName'];
		 
		  ?><option value='<? echo $sid ?>' <? if($cancel[0]==$sid){?> selected='selected' <? }  ?>  ><? echo  $sname ?></option> <?	
		}	
		
}

public static function GetListCanceled()
{
   $st=sprintf("SELECT * FROM Canceled");
   $query=mysql_query($st) or die(mysql_error().' '.$st);	
	echo "<option value='none' selected='selected' >בחר סיבת דחיה</option>";	
	while($row=mysql_fetch_assoc($query))
		{
          $sid=$row['Id'];
		  $sname=$row['CanceledName'];
		  echo "<option value='$sid' >$sname</option>";	
		}	
}
public static function GetNameListCanceled($id_canceled)
{
	$st="SELECT * FROM `Canceled` WHERE `Id`=$id_canceled";
	$query=mysql_query($st) or die(mysql_error().' ' .$st);
	if(mysql_affected_rows()>0)
	 {
		 $row=mysql_fetch_object($query);
		 return $row->CanceledName;
	 }
	  else 
	   {
		 return 0;
	   }
		 
}
public static function getProjectInOrderName()
{
  	$st="SELECT * FROM `project` WHERE `project_status`=1";
	$query=mysql_query($st) or die(mysql_error().' ' .$st);
	if(mysql_affected_rows()>0)
	 { 
	     $str="";
		 while($row=mysql_fetch_object($query))
		  {
			   $str.="  $row->project_name  \n" ;
		  }
		 return $str;
	 }
	  else 
	   {
		 return 0;
	   }
}
public static function sendWeeklyReport()
{
	$arr_admin = user::get_user_by_type(1);
	$in_order=project::get_in_development(1);
	$in_developmen=project::get_in_development(2);
	$in_Produced=project::get_in_development(3);
	$in_new=task::get_task_Treatment(1);
	$in_finish=task::get_task_treatment(4);
	$getProjectInOrderName = project::getProjectInOrderName(); 
	
			 
	  foreach($arr_admin as $value)
	 {  

 $body=" שלום $value->user_name , \n
 להלן סיכום שבועי של חברתך במערכת ה-CRM  \n
 פרויקטים בשלב המכירה: $in_order  \n
 פרויקטים בפיתוח: $in_developmen \n
 פרויקטים בסביבת היצור: $in_Produced \n
 \n
 נפתחו השבוע $in_new  פניות \n
 נסגרו השבוע $in_finish פניות \n
 הפרויקטים הבאים עדיין בשלב המכירה:\n $getProjectInOrderName 
 שלך צוות ה CRM  ";
	     //$temp_user = new user;
	  	// $temp_user->getby_id($value->user_id);
		 
		  if($value->send_mail==1)
	 	 {  
		    
		    $mail = new PHPMailer();
			$mail->IsSMTP(); // flag is using smtp
			$mail->IsSMTP(); // flag is using smtp
			$mail->SMTPAuth   = true;                  // enable SMTP authentication
			$mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
			$mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
			$mail->Port       = 465;                   // set the SMTP port
			
			$mail->Username   = "do_not_reply@restartit.co.il";  // GMAIL username
			$mail->Password   = "restart4mail";            // GMAIL password
			$mail->IsHTML(true);
			$mail->FromName="RestartIT CRM";
			$mail->From = "restartit@email.com"; 
			$mail->AddAddress("$value->user_mail"); // To address
			$mail->Subject ="דוח שבועי מהמערכת CRM";
			$mail->Body = "$body";
			$mail->WordWrap = 150;// allows 50 chars in each line
			$mail->CharSet = 'UTF-8';
		
			if(true)
			{
			 //echo "Message was not sent";
			// echo "Mailer Error: " . $mail->ErrorInfo;
			} 
			else { //echo "Message was sent";
			     }
	 	 }
	   }
}

public static function ReverseDate($date)
{
 $arr=explode('-',$date);
 return $arr[2].'-'.$arr[1].'-'.$arr[0];	
}
}

 
?>